package com.hqq.behaviour.observer.generics;

import com.hqq.behaviour.observer.WeatherType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * GWeather
 * Created by heqianqian on 2017/6/17.
 */
public class GWeather extends Observable<GWeather, Race, WeatherType> {

    private static final Logger LOGGER = LoggerFactory.getLogger(GWeather.class);

    private WeatherType currentWeather;

    public GWeather() {
        currentWeather = WeatherType.SUNNY;
    }

    public void timePassed() {
        WeatherType[] enumValues = WeatherType.values();
        currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length];
        LOGGER.info("The weather changed to {}.", currentWeather);
        notifyObservers(currentWeather);
    }

    private void notifyObservers(WeatherType currentWeather) {
        notifyObserver(currentWeather);
    }
}
